import 'dart:core' as prefix0;
import 'dart:core';
import 'package:flutter/material.dart';
import '../../flutter_dk_form.dart';

/// 展示标签（可点击）
/// [data]：标签数据
/// [onClick]：标签点击回调
class ShowLabelWidget extends StatefulWidget {
  final List data;
  final Function onClick;

  ShowLabelWidget({this.data, this.onClick});

  @override
  State<StatefulWidget> createState() {
    return _ShowLabelWidgetState();
  }
}

class _ShowLabelWidgetState extends State<ShowLabelWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        children: <Widget>[
          Container(
            width: double.infinity,
            child: Wrap(
              runAlignment: WrapAlignment.center,
              spacing: 10,
              runSpacing: 19,
              children: _getWidgetList(widget.data),
            ),
            padding: EdgeInsets.only(left: 16, right: 16, top: 10, bottom: 10),
          ),
        ],
      ),
    );
  }

  List<Widget> _getWidgetList(List data) {
    List<Widget> widgetList = List();
    if (data != null) {
      data.forEach((item) {
        widgetList.add(GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () {
            if (widget.onClick != null) {
              widget.onClick(item);
            }
          },
          child: Container(
//            constraints: BoxConstraints(
//              minWidth: 77,
//            ),
            height: 30,
            child: Text(
              item.content,
              style: TextStyle(
                  color: Color(item.selected ? 0xFF50D0D9 : 0xFF999999),
                  fontSize: 16),
              textAlign: TextAlign.center,
            ),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.all(
                  Radius.circular(2),
                ),
//                color: item.selected ? Color(0xFF50D0D9) : Color(0xFF999999),
                border: Border.all(
                    color:
                        item.selected ? Color(0xFF50D0D9) : Color(0xFF999999),
                    width: 1)),
            padding: EdgeInsets.only(left: 10, right: 10, top: 3),
          ),
        ));
      });
    }
    return widgetList;
  }
}
